<?php


namespace app\common\command;

use app\http\Http;
use app\sys\model\Dict;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\Db;
use think\facade\Env;
use wework\WeWork;
use app\sys\model\QyeDepartment as QyeDepartmentModel;

class QyeDepartment extends Command
{
    protected function configure()
    {
        $this->setName('qye_department')
            ->setDescription('企业微信获取部门');
    }

    protected function execute(Input $input, Output $output)
    {
        $corpId = Env::get("QYE.CORPID");
        $secret = Env::get("QYE.APP_SECRET");

//        Db::startTrans();
//        try {
            $we = new WeWork($corpId, $secret);
            $res = $we->departmentList();
            QyeDepartmentModel::add($res);
            Db::commit();
            $output->writeln("qye_department success");
//        } catch (\Exception $e) {
//            $output->writeln("qye_department false");
//            Db::rollback();
//        }
    }

}